//
//  UIImage+M3.m
// 
//
//  Created by 徐盟 on 2023/6/9.
//

#import "UIImage+M3.h"

@implementation UIImage (M3)

+(instancetype) imageWithImageName:(NSString *) name andSize:(CGSize) size
{
    CGFloat scale = [[UIScreen mainScreen]scale];
    UIImage * img = [UIImage imageNamed:name];
    UIGraphicsBeginImageContextWithOptions(size, NO, scale);
    [img drawInRect:CGRectMake(0,0,size.width,size.height)];
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
}
+(instancetype) color:(UIColor *) color andSize:(CGSize) size
{
    CGRect rect = CGRectMake(0, 0, size.width, size.height);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}
+(instancetype) colorWithHexString:(NSString *) hexString andSize:(CGSize) size
{
    return [self color:[UIColor colorWithHexString:hexString] andSize:size];
}


@end
